<?php
	header("Content-Type:text/html;   charset=utf8");
	error_reporting(E_ALL^E_NOTICE);

	



	// 定义变量并设置为空值
	$name_Err = $stu_id_Err = $class_Err = $qq_Err = $ggroup_Err= "";
	$name = $stu_id = $class = $tel = $qq = $ggroup = "";



	function test_input($data) {
		   $data = trim($data);
		   $data = stripslashes($data);
		   $data = htmlspecialchars($data);
		   return $data;
	}

	if ($_SERVER["REQUEST_METHOD"] == "POST") {
	   if (empty($_POST["name"])) {
	     $name_Err = "姓名是必填的";

	   } else {
	     $name = test_input($_POST["name"]);
	     }
	   
	   if (empty($_POST["stu_id"])) {
	     $stu_id_Err = "学号是必填的";
	   } else {
	     $stu_id = test_input($_POST["stu_id"]);
	   }

	   if (empty($_POST["class"])) {
	     $class_Err = "班级是必填的";
	   } else {
	     $class = test_input($_POST["class"]);
	   }

	   if (empty($_POST["tel"])) {
	     $tel_Err = "电话是必填的";
	   } else {
	     $tel = test_input($_POST["tel"]);
	   }

	   if (empty($_POST["qq"])) {
	     $qq_Err = "qq是必填的";
	   } else {
	     $qq = test_input($_POST["qq"]);
	   }

	   if (empty($_POST["ggroup"])) {
	     $ggroup_Err = "报名组别是必填的";
	   } else {
	     $ggroup = test_input($_POST["ggroup"]);
	   }

	
	echo $name_Err."<br/>";
	echo $stu_id_Err."<br/>";
	echo $class_Err."<br/>" ;
	echo $qq_Err."<br/>";
	echo $ggroup_Err."<br/>";

	// header("Location: ./index.php"); 
	
}

		if($name_Err==null&&$stu_id_Err==null&&$class_Err==null&&$qq_Err==null&&$ggroup_Err==null){
		$con = mysql_connect("localhost","root","");
		mysql_query("SET NAMES 'UTF8'");//防止数据乱码，很重要哦！！！！！
	if(!$con)
	  {
	  die('Could not connect: ' . mysql_error());
	  }
	mysql_select_db("sign_up", $con);
	echo "test";
	$sql="INSERT INTO sign_up(name,stu_id,class,tel,qq,ggroup)
	VALUES
	('$name','$stu_id','$class','$tel','$qq','$ggroup')";
	if(!mysql_query($sql,$con))
	  die('Error: ' . mysql_error());
	else
	  // echo"登录成功！";
		 echo "<script>alert('您已成功报名启明星！');history.back();</script>";
		mysql_close($con);
	}
?>
<p><a href="./sign_up.php">返回主页！</a></p>
